package com.gitee.wsl.io.channel

import kotlinx.coroutines.Job

/**
 * Ensures that when the given job is canceled, the ByteChannel is canceled with the same exception.
 */
 fun ByteChannel.attachJob(job: Job) {
    job.invokeOnCompletion {
        if (it != null) {
            cancel(it)
        }
    }
}

/**
 * Ensures that when the given job is canceled, the ByteChannel is canceled with the same exception.
 */
 fun ByteChannel.attachJob(job: ChannelJob) {
    attachJob(job.job)
}

